/***************************************************************************
                          mstl.h  -  Mini-STL library
                             -------------------
    begin                : Mon May 6 2002
    copyright            : (C) 2002 by Michiel Visser
    email                :
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

//---------------------------------------------------------------------------
#ifndef __MSTL_DBG_H__
#define __MSTL_DBG_H__
//---------------------------------------------------------------------------

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

// { ------ configuration --------
#ifdef DEBUG
#define IFDEBUG(x) x
#define ENABLE_ASSERT
//#define TRACE_IN_MEMORY

#define MALLOC_EXCLUSIVENESS_TEST
///#define MALLOC_COUNT // counts the different types of memory allocation
#define MALLOC_BOUNDARY_TEST // adds and tests a boundary round variable memory allocations
#define MALLOC_FREE_TEST // tests whether freeing memblock is ok
#define MALLOC_WIPE // this increases the likelyhood a program will generate an error on usage of invalidated memory
#define MALLOC_FILO // use in combination with MALLOC_WIPE
//#define MALLOC_INTEGRITYCHECK // todo: fix
//#define MALLOC_VERBOSE_GC
//#define VERBOSE_OLT // Object LifeTime
#define IFDEBUGDEEP(x) //x

#else
#define IFDEBUG(x)
#define IFDEBUGDEEP(x)
#endif
// } ------------------------

#define _DEBUG_ENABLE 1
#include <handy.h>

#ifdef MALLOC_VERBOSE_GC
#define IF_MALLOC_VERBOSE_GC(x) x
#else
#define IF_MALLOC_VERBOSE_GC(x)
#endif

#ifdef MALLOC_INTEGRITYCHECK
#define IF_MALLOC_INTEGRITYCHECK(x) x
#else
#define IF_MALLOC_INTEGRITYCHECK(x)
#endif
#ifdef MALLOC_COUNT
extern struct MCount { int variable; int block; int deletionCandidate; } mcounts;
#endif
#ifdef ENABLE_ASSERT
extern int zeroDummy;
#define DIV_BY_ZERO(x) { printf("DIV_BY_ZERO"); _TRACE; zeroDummy=(int)(x)/zeroDummy;}
#define ASSERT(cond) { if (!(cond)) { DIV_BY_ZERO(#cond) } }
#else
#define ASSERT(cond)
#endif
#ifdef VERBOSE_OLT
#define IF_VERBOSE_OLT(x) x
#else
#define IF_VERBOSE_OLT(x)
#endif

IFDEBUG(extern int dbgvars[16];)

#ifdef TRACE_IN_MEMORY
typedef struct { short id; short line;} dbg_lines_struct;
extern dbg_lines_struct dbg_lines[16];
extern int dbg_li;
#define TRC(ID) { dbg_lines[dbg_li].id=ID; dbg_lines[dbg_li].line=__LINE__; dbg_li=(dbg_li+1)&15;dbg_lines[dbg_li].id=11111; } 
#endif

#endif /* __MSTL_DBG_H__ */

